package com.black.platform.fdfs.service.impl;

import com.black.platform.fdfs.service.FastDfsService;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author linwenfeng
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FastDfsServiceImpl implements FastDfsService {

    private final FastFileStorageClient storageClient;

    @Override
    public String upload(MultipartFile file, String fileExtName) throws Exception {
        StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), fileExtName, null);
        if (storePath != null) {
            return storePath.getFullPath();
        }
        return null;
    }
}
